#ifndef _GB_MEMORY_H_
#define _GB_MEMORY_H_

#include <string.h>
#include <stdlib.h>
#include "cartridge.h"

/*
	COME INDIRIZZA LO Z80 SUL GAMEBOY
	
	0000-3FFF*   16KB ROM Bank 00     (in cartridge, fixed at bank 00) (cartridge.h)
	4000-7FFF*   16KB ROM Bank 01..NN (in cartridge, switchable bank number) (cartridge.h)
	8000-9FFF   8KB Video RAM (VRAM) (switchable bank 0-1 in CGB Mode)
	A000-BFFF*   8KB External RAM     (in cartridge, switchable bank, if any) (cartridge.h)
	C000-CFFF*   4KB Work RAM Bank 0 (WRAM) (memory.h inevitabilmente, tanto è solo zona di lavoro, non si interfaccia a niente)
	D000-DFFF*   4KB Work RAM Bank 1 (WRAM)  (switchable bank 1-7 in CGB Mode) (memory.h)
	E000-FDFF*   Same as C000-DDFF (ECHO)    (typically not used) (memory.h)
	FE00-FE9F   Sprite Attribute Table (OAM)
	FEA0-FEFF   Not Usable
	FF00-FF7F   I/O Ports
	FF80-FFFE   High RAM (HRAM)
	FFFF        Interrupt Enable Register
	
	in effetti non so se conviene suddividere in più file, per ora c'è il controllore della cart, magari serve controllore per LCD e per l'I/O generico

*/

typedef unsigned char UINT8;
//typedef unsigned short UINT16;

struct MEM_MAP
{
	/* TODO: la vram va spostata nel file che gestirà il display */
	UINT8 *vram_bank; // 0x8000-0x9FFF (switchabile 2 banchi in CGB)
	UINT8 *wram_bank_0; // 0xC000-0xCFFF - 4kb working RAM
	UINT8 *wram_bank_1; // 0xD000-0xDFFF - 4kb working RAM (switchabile 8 banchi in CGB)
	UINT8 *oam_table;  // 0xFE00-0xFE9F - sprite attribute table	
};

extern MEM_MAP memory;

UINT8 mem_read(UINT16 address);
void mem_write(UINT16 address, UINT8 value);
void mem_init();
UINT16 rom_size();


#endif